package edu.xmut.yuepai.blog.controller;


import edu.xmut.yuepai.blog.service.BlogService;
import edu.xmut.yuepai.common.result.R;
import edu.xmut.yuepai.model.form.BlogPublishForm;
import edu.xmut.yuepai.model.vo.BlogDetailVo;
import edu.xmut.yuepai.model.vo.PageVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/blog")
public class BlogController {

    @Resource
    private BlogService blogService;


    @GetMapping("/recommend/{pageNum}/{pageSize}")
    public R recommend(@PathVariable("pageNum")
                       Integer pageNum,
                       @PathVariable("pageSize")
                       Integer pageSize) {
        PageVO pageVO = blogService.recommend(pageNum, pageSize);
        return R.ok(pageVO);
    }

    @GetMapping("/details/{id}")
    public R getBlogDetail(@PathVariable("id")
                           Long id) {
        BlogDetailVo blogDetailVo = blogService.getBlogDetail(id);
        return R.ok(blogDetailVo);
    }

    @PostMapping("/publish")
    public Long publish(@RequestBody BlogPublishForm blogPublishForm, @RequestParam("ip") String ip) {
        return blogService.publish(blogPublishForm, ip);
    }


}
